﻿using MediatR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using wt.wine.Application.Common.Interfaces;
using wt.wine.Application.Common.Models;

namespace wt.wine.Application.ManageSkutable.Queries
{
    /// <summary>
    /// 【经销商】产品列表
    /// </summary>
    public class GetSkutableListQueries : IRequest<Json<PaginatedList<GetSkutableListDTO>>>
    {
        public int pageIndex { get; set; }
        public int pageSize { get; set; }
    }

    public class GetSkutableListQueriesHandler : IRequestHandler<GetSkutableListQueries, Json<PaginatedList<GetSkutableListDTO>>>
    {
        private readonly ICurrentUserService _icurrentUserServices;
        private readonly IskutableRepository _iskutableRepository;
        public GetSkutableListQueriesHandler(ICurrentUserService icurrentUserServices, IskutableRepository iskutableRepository)
        {
            _icurrentUserServices = icurrentUserServices;
            _iskutableRepository = iskutableRepository;
        }
        public async Task<Json<PaginatedList<GetSkutableListDTO>>> Handle(GetSkutableListQueries request, CancellationToken cancellationToken)
        {
            int userid = _icurrentUserServices.GetUserId();
            PaginatedList<GetSkutableListDTO> model = new PaginatedList<GetSkutableListDTO>(new List<GetSkutableListDTO>() { }, 0, 0, 0);
            if (userid <= 0)
            {
                return Json<PaginatedList<GetSkutableListDTO>>.Failed("请先登录");
            }
            else if (request.pageIndex <= 0 || (request.pageSize <= 0 || request.pageSize >= 1000))
            {
                return Json<PaginatedList<GetSkutableListDTO>>.Failed("参数不合法");
            }
            else {
                model = await _iskutableRepository.GetSkuTableList(userid, request.pageIndex, request.pageSize, cancellationToken);
                return Json<PaginatedList<GetSkutableListDTO>>.Success("查询成功",model);
            }
        }
    }
}
